Replication Materials for:
==========================

  Denis Cohen
  Between Strategy and Protest: How Policy Demand, Political Dissatisfaction, 
  and Strategic Incentives Matter for Far Right Voting
  
  In case of problems or questions, please contact Denis Cohen. Contact
  details are available at https://denis-cohen.github.io
  
  
Overview
========

  Next to occasional descriptive statistics, the paper and online appendix
  feature Bayesian analyses of far right voting. For the main analysis
  (and corresponding alternative specifications reported in the online
  appendix), the analyses are run separately (with different model 
  specifications) for parties in opposition and parties in government.
  
  These analyses use and generate different types of files, which are stored
  in the following folders:
  
  1 /dat:     multiply imputed data sets
  2 /fun:     user-written R functions and function "edvreg.R" (Lewis and Linzer,
              2005)
  3 /mod:     model code, written in Stan
  4 /run:     R scripts, which specify model data, model specification, and
              details of Bayesian estimation; run Bayesian estimation (typically,
              two sequential chains ran in parallel across five cores); generate
              quantities of interest (predicted values and/or average marginal 
              effects)
  5 /post:    R scripts for post-processing (e.g., figure and table generation)
  6 /est_par: raw parameter estimates (separate files for each imputation); 
              typically not of primary interest; only included for three 
              specifications reported as tables in the online appendix
  7 /est_qoi: predicted quantities of interest (predicted values and/or average 
              marginal effects), on which the reported figures are based
  8 /tex      TeX files for table entries and referenced numerical estimates
  9 /fig:     PDF/PNG files of figures included in main text + online appendix
  
  Contents of folders (1)-(5) are required for full replication. Contents of 
  folders (6)-(9) are generated during replication. If you start from scratch,
  copy and paste folders (1)-(5) to your R working directory and create empty 
  folders (6)-(9) by running:
  
    sapply(c("est_par", "est_qoi", "tex", "fig"), dir.create)
  
  For complete replication of a given table or figure, one must first run all
  scripts in (4) "~/run"" and then those in (5) "~/post". 
  For generating figures and tables based on the estimates included in 
  folders (6) and (7), one only needs to run the scripts in (5) "~/post".
  
  Full correspondence between the evidence in the paper and the various files
  is displayed in tabular form below.
  
  
System Requirements, Run Time, and Version Control
==================================================

  Parallel estimation of the Bayesian analyses was performed on a remote
  Linux server with 8 cores and 16GB RAM. Parallel estimation (via the R
  package "parallel") uses OS-forking (not available on Windows). 
  System and version information below:
  
  > sessionInfo()
  R version 3.4.2 (2017-09-28)
  Platform: x86_64-pc-linux-gnu (64-bit)
  Running under: CentOS Linux 7 (Core)
  
  > packageVersion("rstan")
  [1] '2.18.2'
  > packageVersion("parallel")
  [1] '3.4.2'
  
  See https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started for an
  installation guide for the 'rstan' package and required dependencies.

  The following packages were used for the processing of quantities of interest
  for tables and figures:

  > packageVersion("xtable")
  [1] '1.8.3'
  > packageVersion("MASS")
  [1] '7.3.51.1'
  > packageVersion("abind")
  [1] '1.4.5'
  > packageVersion("plot3D")
  [1] '1.1.1'
  > packageVersion("plyr")
  [1] '1.8.4'
  
  The run time of a single analysis (running sets of two sequential chains in 
  parallel across five imputations) is approx. 2 to 4.5 hours for models of 
  voting for oppositional far right parties and approx. 20 to 30 minutes for
  models of voting for far right parties in government. Additionally, 
  post-estimation calculation of the respective quantities of interest may take
  up to several hours per analysis.


Notes
=====
  1. For any analysis, R code in "~/run":
     - loads required R packages
     - loads and processes multiply imputed data from "~/dat"
     - sources required user-written functions from "~/fun"
     - loads and compiles .stan model code from "~/mod"
     - in parallel across M imputations, runs sets of two sequential chains
       and saves imputation-specific parameter estimates to "~/est_par"
     - in parallel across M imputations, calculates quantities of interest as a
       function of parameters and data and saves objects to "~/est_qoi"
  2. R code "~/post/figures.R"
     - loads required functions, data, and estimates from "~/fun","~/dat", 
       "~/est_par", and "~/est_qoi"
     - post-processes data and estimates for the generation of all figures in 
       the main text and online appendix (saved in "~/fig"). Also generates TeX
       stubs of numerical estimates (saved in "~/tex").
  3. R code "~/post/tables.R"
     - loads required functions, data, and estimates from "~/fun","~/dat", and
       "~/est_par"
     - post-processes data and estimates for the generation of Tables A.1, A.3, 
       and A.4. Numerical entries of these tables saved in "~/tex"; table 
       formatting (e.g. labeling and indentation) done manually.
       
Correspondence
==============
Note: Some estimates are used for multiple Figures. To avoid repeated estimation 
      of the same model, do not re-run scripts in parentheses.

Object    /run:                                         /mod:                            /dat:             /post:       /fig: /tab:        
===========================================================================================================================================
Main Text                                                                                                                                  
===========================================================================================================================================
Table 1   [manually generated]                          ---                              ---                ---         ---                
Fig. 1    04_vi_default_0w2.R, 04_fe_default_1w2.R      04_vi.stan, 04_fe.stan           ees_mp.RData       figures.R   def_main.pdf       
Fig. 2    (04_vi_default_0w2.R, 04_fe_default_1w2.R)    04_vi.stan, 04_fe.stan           ees_mp.RData       figures.R   xb.pdf             
Fig. 3    [based on multiple estimates]^1               ---                              ---                figures.R   def_robust.pdf     
                                                                                                                                           
Appendix                                                                                                                                   
===========================================================================================================================================
Table A.1 ---                                           ---                              ees_mp.RData       tables.R    tablea1.tex        
Fig A.1   04_vi_default_0w2_25.R,04_fe_default_1w2_25   04_vi.stan, 04_fe.stan           ees_mp25.RData     figures.R   def_m25.pdf        
Fig A.2   04_vi_hlm_0w2.R, 04_fe_hlm_1w2.R              04_vi_hlm.stan, 04_fe_hlm.stan   ees_mp.RData       figures.R   def_hlm.pdf        
Fig A.3   04_vi_tpm_0w2.R, 04_fe_tpm_1w2.R              04_vi_tpm.stan, 04_fe_tpm.stan   ees_mp.RData       figures.R   def_tpm.pdf        
Fig A.4   06_tobit.R                                    06_tobit.stan                    ees_mp.RData       figures.R   unp_tobit.pdf      
Fig A.5   06_lm.R                                       06_lm.stan                       ees_mp.RData       figures.R   unp_lm.pdf         
Fig A.6   06_tpm.R                                      06_tpm.stan                      ees_mp.RData       figures.R   unp_tpm.pdf        
Fig A.7   (06_tobit.R)                                  06_tobit.stan                    ees_mp.RData       figures.R   unp_sub1.pdf       
Fig A.8   (06_tobit.R)                                  06_tobit.stan                    ees_mp.RData       figures.R   unp_sub2.pdf       
Fig A.9   (06_tobit.R)                                  06_tobit.stan                    ees_mp.RData       figures.R   unp_add.pdf        
Fig A.10  ---                                           ---                              ees_mp.RData       figures.R   hist.pdf           
Fig A.11  04_vi_norm_0w2.R, 04_fe_norm_1w2.R            04_vi.stan, 04_fe.stan           ees_mp.RData       figures.R   def_norm.pdf       
Fig A.12  04_vi_deb_0w2.R, 04_fe_deb_1w2.R              04_vi.stan, 04_fe.stan           ees_mp.RData       figures.R   def_deb.pdf        
Fig A.13  ---                                           ---                              ees_mp.RData       figures.R   cors.pdf           
Fig A.14  04_vi_stf_0w2.R, 04_fe_stf_1w2.R              04_vi.stan, 04_fe.stan           ees_mp.RData       figures.R   def_stf.pdf        
Fig A.15  04_vi_8909_0w2.R, (04_fe_default_1w2.R)       04_vi.stan, 04_fe.stan           ees_mp.RData       figures.R   def_8909.pdf       
Fig A.16  04_vi_logit_0.R, 04_vi_logit_1.R              04_vi_logit.stan                 ess_bsap_am.RData  figures.R   def_ess.pdf        
Fig A.17  04_vi_seats_0w2.R, (04_fe_default_1w2.R)      04_vi.stan, 04_fe.stan           ees_mp.RData       figures.R   def_votes.pdf      
Fig A.18  04_vi_ep_0w2.R, (04_fe_default_1w2.R)         04_vi.stan, 04_fe.stan           ees_mp.RData       figures.R   def_ep.pdf         
Fig A.19  04_vi_polls_0w2.R, (04_fe_default_1w2.R)      04_vi.stan, 04_fe.stan           ees_mp.RData       figures.R   def_polls.pdf      
Fig A.20  04_vi_complr_0w2.R, (04_fe_default_1w2.R)     04_vi.stan, 04_fe.stan           ees_mp.RData       figures.R   def_comp.lr.pdf    
Fig A.21  04_vi_compcult_0w2.R, (04_fe_default_1w2.R)   04_vi.stan, 04_fe.stan           ees_mp.RData       figures.R   def_comp.cult.pdf  
Table A.2 [manually generated]                          ---                              ---	              ---         ---                 
Fig A.22  04_vi_aecomp_0w2.R, (04_fe_default_1w2.R)     04_vi.stan, 04_fe.stan           ees_mp.RData       figures.R   def_compae.pdf     
Fig A.23  04_vi_percna_0w2.R, (04_fe_default_1w2.R)     04_vi.stan, 04_fe.stan           ees_mp.RData       figures.R   def_perc.na.pdf    
Fig A.24  04_vi_control_0w2.R,  04_fe_control_1w2.R     04_vi.stan, 04_fe.stan           ees_mp.RData       figures.R   def_control.pdf    
Fig A.25  07_3D_0w2.R, 07_3D_1w2.R                      07_vi_3D.stan, 07_fe_3D.stan     ees_3D.RData       figures.R   b_multimfxw.pdf    
Table A.3 [based on multiple estimates]^2               ---                              ---                tables.R    tablea3_*.tex      
Table A.4 [based on multiple estimates]^3               ---                              ---                tables.R    tablea4_*.tex      
===========================================================================================================================================
^1: Figure combines estimates from Fig. 1, Fig A.1-A.3, A.12, A.14, A.15, A.17-A.24
^2: Table combines estimates generated per 04_vi_default_0w2.R, 04_vi_hlm_0w2.R, and 04_vi_tpm_0w2.R
^3: Table combines estimates generated per04_fe_default_1w2.R, 04_fe_hlm_1w2.R, 04_fe_tpm_1w2.R